﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Aspose.Cells;
using Microsoft.AspNetCore.Mvc;
using SHZY.BaseData.Entitys;
using SHZY.Business.Entitys.Dto.QmsBusiInspectionlot;
using SHZY.Business.Entitys;
using SHZY.Business.Interfaces;
using SHZY.DependencyInjection;
using SHZY.DynamicApiController;
using Spire.Presentation;
using SqlSugar;
using SHZY.Extend.Entitys;
using Microsoft.AspNetCore.Hosting;
using SHZY.Common.FR;
using Mapster;
using SHZY.BaseData.Entitys.Dto.QmsBaseDefect;

namespace SHZY.Business
{
    [ApiDescriptionSettings(Tag = "Business", Name = "FastReport", Order = 200)]
    [Route("api/Business/[controller]")]
    public class FastReportService : IQmsBusiInspectionService, IDynamicApiController, ITransient
    {
        /// <summary>
        /// 服务基础仓储.
        /// </summary>
        private readonly ISqlSugarRepository<EmployeeEntity> _repository;

        public FastReportService(ISqlSugarRepository<EmployeeEntity> repository)
        {
            _repository = repository;
        }

        public Task AutoGenerateInspection()
        {
            throw new NotImplementedException();
        }


        /// <summary>
        /// 获取报检单Form.
        /// </summary>
        /// <param name="id">主键值.</param>
        /// <returns></returns>
        [HttpGet("{id}")]
        public async Task<dynamic> GetInfo(string id)
        {
            var result = await _repository.FirstOrDefaultAsync(x => x.Id == id && x.DeleteMark == null);

            Dictionary<string, string> dic = new Dictionary<string, string>();
            dic.Add("enCode", result.EnCode);
            dic.Add("fullName", result.FullName);
            dic.Add("gender", result.Gender);
            dic.Add("departmentName", result.DepartmentName);

            List<QmsBaseDefectListOutput> qmslist = new List<QmsBaseDefectListOutput>();
            qmslist.Add(new QmsBaseDefectListOutput() { id = "1", name = "111" });
            qmslist.Add(new QmsBaseDefectListOutput() { id = "2", name = "222" });
            qmslist.Add(new QmsBaseDefectListOutput() { id = "3", name = "333" });
            qmslist.Add(new QmsBaseDefectListOutput() { id = "4", name = "44444444" });
            var ob = qmslist.Adapt<List<object>>();

            var dic1 = new Dictionary<string, List<object>>();
            dic1.Add("resultRef", ob);
            var ms = CreateFR.ExportFastReportPDF(dic1, dic, "report.frx");
            return ms;
        }
    }
}
